define(function(require){
	
	var $=require("jq");
	var PZ_Dialog=require("pz_use_dialog.js");
	
//	var code = $('#code').val();
//	var msg = $('#message').val();
//	
//	if(code == 'PE_400'){
//		if(msg != null && msg != '' && msg.length > 0){
//			var tips=new PZ_Dialog({
//				  type:"alert",
//				  height:107,
//				  tipsText:'会员不是VIP会员',
//				  buttonCancelText:"知道了", 
//				  mask:0.3,
//				  isDrag:true
//			});
//		}
//	}
	
	$('.addItem').bind('click',function(){
		alert('');
		var data_canbuy = $(this).attr('data_canbuy');
		var data_article = $(this).attr('data_article');
		if(data_canbuy == '0'){
			var tips=new PZ_Dialog({
				  type:"alert",
				  height:107,
				  tipsText:'该商品买完了.',
				  buttonCancelText:"知道了", 
				  mask:0.3,
				  isDrag:true
			});
			return;
		}else{
			var params = {};
			params['productId'] = data_article;
			params['amount'] = 1;
			params['agentId'] = -1;
			params['m_id'] = 0;
			$.ajax({
				type : "get",
				async: false,
				url : "/addItem.do",
				data:params,
				dataType : "json",
				success : function(result){
					var code = result['code'];
					var msg = result['message'];
					var state = result['state'];
					
					if(code == 'PE_200'){
						if(msg != null && msg.length > 0){
							var tips=new PZ_Dialog({
								  type:"alert",
								  height:107,
								  tipsText:msg,
								  buttonCancelText:"知道了", 
								  mask:0.3,
								  callBack:function(){
									  window.location.href="/cartList.do";
								  },
								  isDrag:true
							});
						}else{
							window.location.href="/cartList.do";
						}
					}else if(code == 'PE_400'){
						var tips=new PZ_Dialog({
							  type:"alert",
							  height:107,
							  tipsText:'会员不是VIP会员.',
							  buttonCancelText:"知道了", 
							  mask:0.3,
							  isDrag:true
						});
					}else if (code == 'PE_399'){
						var tips=new PZ_Dialog({
							  type:"alert",
							  height:107,
							  tipsText:'您尚未登录不能购买产品.',
							  buttonCancelText:"知道了", 
							  mask:0.3,
							  callBack:function(){
								  window.location.href="/login.do?toUrl=/pointExt/goods.do";
							  },
							  isDrag:true
						});
					}
					
					
				}
			});
		}
	});
});